package com.bacel.nb.product.web.util;

import com.bacel.nb.product.core.domain.Device;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Pipeline;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/9/4 0004.
 */
public class AddToRedis {
    public static void addToRedis(List<Device> list) {
        try{
            Jedis redis = RedisPoolUtils.getJedisObject();
            Pipeline p = redis.pipelined();
            Map<String,String> data = new HashMap<>();
            for (int i=0;i<list.size();i++) {
                if (list.get(i).getAppByAppid()!=null){
                    Device device = list.get(i);
                    data.put(device.getSn(),device.getAppByAppid().getPushaddress());
                }
            }
            p.hmset("deviceinfo",data);
            p.sync();
            p.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
